package com.evildog.workspace.system.application.controller;

import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.system.application.bo.DictDataListBO;
import com.evildog.workspace.system.application.convert.DictDataConvert;
import com.evildog.workspace.system.application.model.DictDataListParam;
import com.evildog.workspace.system.application.model.DictDataParam;
import com.evildog.workspace.system.application.service.DictDataService;
import com.evildog.workspace.system.application.vo.DictDataListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * dictData Controller
    字典数据表
 * </p>
 *
 * @author evildog
 * @since 2020-08-06
 */
@RestController
@RequestMapping("/dict-data")
@AllArgsConstructor
@Api(tags = "dictData相关接口")
public class DictDataController {

    private DictDataService dictDataService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody DictDataParam dictDataParam) {
        return ResultGenerator.status(dictDataService.save(DictDataConvert.INSTANCE.convert(dictDataParam)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(dictDataService.removeById(id));
    }

    @DeleteMapping("/batch-remove")
    @ApiOperation(value = "批量删除接口")
    public Result<Boolean> removeByIds(@RequestParam("ids") List<Integer> ids) {
        return ResultGenerator.status(dictDataService.removeByIds(ids));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新接口")
    public Result<Boolean> updateById(@PathVariable("id") Long id,@RequestBody DictDataParam dictDataParam) {
        return ResultGenerator.status(dictDataService.updateById(id, DictDataConvert.INSTANCE.convert(dictDataParam)));
    }

    @GetMapping
    @ApiOperation(value = "表List查询接口")
    public Result<List<DictDataListVO>> getList(DictDataListParam dictDataListParam){
        List<DictDataListBO> dictDataListBO = dictDataService.getList(
                        QueryConditionUtils.getQueryCondition(dictDataListParam),
                        DictDataConvert.INSTANCE.convert(dictDataListParam));
        return ResultGenerator.success(DictDataConvert.INSTANCE.convertVoList(dictDataListBO));
    }

}